#include "PrototypeTool.h"
#include "PlaceCommand.h"
#include "Acceptor.h"
#include "DiagramMan.h"
#include "DiagramFam.h"
#include "../model/UMLObject.h"
#include "../view/UMLCanvas.h"

PrototypeTool::PrototypeTool(DiagramMan& dman, const UMLObject& prototype)
:	Tool(dman), _prototype(prototype.clone())
{
}

PrototypeTool::PrototypeTool(const PrototypeTool& pt)
:	Tool(pt.dman()), _prototype(pt._prototype->clone())
{
}

PrototypeTool& PrototypeTool::operator=(const PrototypeTool& pt)
{
	if (&pt != this)
	{
		/* Clone the prototype, if it exists. */
		_prototype.reset(pt._prototype.get() ? pt._prototype->clone() : NULL);
	}

	return *this;
}

bool PrototypeTool::mouseMoveEvent(QMouseEvent&)
{
	// TODO: ghost box
	
	return false;
}

bool PrototypeTool::mousePressEvent(QMouseEvent& ev)
{
	DiagramFam& active = dman().active();

	// TODO: implement drag-sizing
	PlaceCommand c(active.diagram(), active.canvas(), *_prototype);

	c.prototype().setPosition(tological(ev.pos()));

	active.acceptor().accept(c);

	return true;
}

bool PrototypeTool::mouseReleaseEvent(QMouseEvent&)
{
	// TODO: implement drag-sizing
	
	return false;
}

